<template>
  <div class="ElectricityQualitybox">
    <div class="leftbx">
      <EnterpriseTree @handleClick="handleClick"></EnterpriseTree>
    </div>
    <div class="rightbox">
      <div class="title">{{ treevalue.name }}</div>
      <div class="echatrvo" >
        <div class="little">电压谐波</div>
        <el-table
        border
        :header-cell-style="{'text-align':'center',background:'#f5f5f5'}"
        v-loading="loading"
        height="calc(100% - 18px)"
        style="width: 100%"
        :data="tableData">
          <el-table-column
            prop="name"
            align="center"
            label="">
          </el-table-column>
          <el-table-column
            prop="distortionRate"
            align="right"
            label="畸变率">
          </el-table-column>
          <el-table-column
            v-for="(item,index) in dianyacontent"
            :key="index"
            align="right"
            :prop="index+2+'次'"
            :label="index+2+'次'">
          </el-table-column>
        </el-table>
      </div>
      <div class="echatrvo" ref="dianyajishu"></div>
      <div class="echatrvo">
        <div class="little">电流谐波</div>
        <el-table
        border
        :header-cell-style="{'text-align':'center',background:'#f5f5f5'}"
        v-loading="loadingliu"
        height="calc(100% - 18px)"
        style="width: 100%"
        :data="tableDataliu">
          <el-table-column
            prop="name"
            align="center"
            label="">
          </el-table-column>
          <el-table-column
            prop="distortionRate"
            align="right"
            label="畸变率">
          </el-table-column>
          <el-table-column
            v-for="(item,index) in dianyacontentliu"
            :key="index"
            align="right"
            :prop="index+2+'次'"
            :label="index+2+'次'">
          </el-table-column>
        </el-table>
      </div>
      <div class="echatrvo" ref="dianliujishu"></div>
    </div>
  </div>
</template>

<script>
import {GetEcharts} from '@/utils/echarts'
import request from '@/utils/request'
import EnterpriseTree from '@/components/EnterpriseTree/index.vue'
import * as echarts from 'echarts';
export default {
  name: 'CallPoliceIndex',
  components: {
    EnterpriseTree
  },
  data() {
    return {
      loading: false,
      dianyacontent:'',
      treevalue: {},
      tableData: [],
      loadingliu:false,
      tableDataliu: [],
      dianyacontentliu:''
    };
  },

  mounted() {
    
  },

  methods: {
    handleClick(val){
      this.treevalue = val
      this.geidianyalist()
      this.getjishuech()
      this.geidianliulist()
      this.getdianliujishuech()
    },
    // 获取电压谐波
    async geidianyalist() {
      this.loading=true
      const { data: { list,content } } =await request.get(`pio-microservice-biz/pio/ect/statistical/analysis/power/quality/real/time/list?classId=${this.treevalue.id}&type=2`)
      list.forEach((item, index) => {
        item.valueList.forEach((ele,leiin) => {
          item[leiin+2+'次']=ele
        })
      })
      this.tableData = list
      this.dianyacontent = +content
      this.loading=false
    },
    // 获取电流谐波
    async geidianliulist() {
      this.loadingliu=true
      const { data: { list,content } } =await request.get(`pio-microservice-biz/pio/ect/statistical/analysis/power/quality/real/time/list?classId=${this.treevalue.id}&type=1`)
      list.forEach((item, index) => {
        item.valueList.forEach((ele,leiin) => {
          item[leiin+2+'次']=ele
        })
      })
      this.tableDataliu = list
      this.dianyacontentliu = +content
      this.loadingliu=false
    },
    // 获取电压谐波曲线
    async getjishuech(){
      const { data: { list } } =await request.get(`pio-microservice-biz/pio/ect/statistical/analysis/power/quality/real/time/line?classId=${this.treevalue.id}&type=2`)
      const timePoints=list.find(ele=>ele.datalist.length)?.datalist.map(item=>item.timeReading)
      const series = list.map(ele => {
        return {
          name: ele.name,
          type: 'line',
          smooth: true,
          data: ele.datalist.map(ele => ele.valueReading),
          markPoint: {
            data: [
              { type: 'max', }
            ]
          }
        }
      })
      let option = {
        legend: {
          right:'1%'
        },
        grid: {
          left: '2%',
          right: '1%',
          bottom: '3%',
          containLabel: true
        },
        title: {
          text: '电压谐波畸变率',
          left: '0',
          textStyle: {
            fontSize:'14'
          }
        },
        color:['#ffb637','#10d29d','#db2c34'],
        xAxis: [
          {
            type: 'category',
            data: timePoints,
            axisPointer: {
              type: 'shadow'
            }
          }
        ],
        tooltip: {
          trigger: 'axis'
        },
        yAxis: [
          {
            type: 'value',
            name: '',
          },
        ],
        series: series
      };
      GetEcharts(this,this.$refs.dianyajishu,option)
    },
    // 获取电流谐波曲线
    async getdianliujishuech() {
      const { data: { list } } =await request.get(`pio-microservice-biz/pio/ect/statistical/analysis/power/quality/real/time/line?classId=${this.treevalue.id}&type=1`)
      const timePoints=list.find(ele=>ele.datalist.length)?.datalist.map(item=>item.timeReading)
      const series = list.map(ele => {
        return {
          name: ele.name,
          type: 'line',
          smooth: true,
          data: ele.datalist.map(ele => ele.valueReading),
          markPoint: {
              data: [
                { type: 'max', }
              ]
            }
        }
      })
      let option = {
        legend: {
          right:'1%'
        },
        grid: {
          left: '2%',
          right: '1%',
          bottom: '3%',
          containLabel: true
        },
        title: {
          text: '电流谐波畸变率',
          left: '0',
          textStyle: {
            fontSize:'14'
          }
        },
        color:['#ffb637','#10d29d','#db2c34'],
        xAxis: [
          {
            type: 'category',
            data: timePoints,
            axisPointer: {
              type: 'shadow'
            }
          }
        ],
        tooltip: {
          trigger: 'axis'
        },
        yAxis: [
          {
            type: 'value',
            name: '',
          },
        ],
        series: series
      };
      GetEcharts(this,this.$refs.dianliujishu,option)
    },
  },
};
</script>

<style scoped>
.ElectricityQualitybox{
  height: 100%;
  padding: 10px;
  display: flex;
  .leftbx{
    width: 300px;
    background-color: #fff;
    padding: 20px;
    margin-right: 10px;
  }
  .rightbox{
    width: calc(100% - 310px);
    background-color: #fff;
    padding: 20px;
    height:100%;
    .title{
      font-size: 18px;
      color: #000;
      font-weight: bolder;
      margin-bottom: 10px;
    }
    .echatrvo{
      margin-bottom: 10px;
      height:23%;
      .little{
        font-size: 14px;
        color: #333;
        font-weight: bolder;
      }
    }
  }
}
</style>